<template>
    <view class="content">
        <view class="top">
            <image :src="data.image" class="img"></image>
            <view class="top-right">
                <view class="title">{{data.title}}</view>
                <view class="u-flex">
                    <view class="time">
                        <image src="../../static/icon/time_01.png" class="time-01"></image>
                        <view>活动时间：{{data.start_time}}-{{data.end_time}}</view>
                    </view>
                    <view></view>
                </view>
                <view class="price">￥<text>{{data.order_amount}}</text></view>
            </view>
        </view>
        <view class="box">
            <view class="reason">申请退款原因</view>
            <view class="item" v-for="(item, index) in data.reason" :key="index" @click="choose(item)">
                <image :src="item.isSelect ? '../../static/icon/choose_01.png' : '../../static/icon/choose_02.png'" class="choose-01"></image>
                <view class="item-right">{{item.name}}</view>
            </view>
        </view>
        <view class="btn" @click="doSubmit">立即退款</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                id: '',
                data: {},
            };
        },
        onLoad(option) {
            this.id = option.id
            this.getData()
        },
        methods: {
            doSubmit() {
                var rid = ''
                this.data.reason.forEach(ii => {
                    if (ii.isSelect) {
                        rid = ii.id
                    }
                })
                if (!rid) {
                    this.$toast('请选择申请退款原因');
                    return
                }
                this.$ajax('instant_refund', {
                    user_token: this.$getSync('userToken'),
                    id: this.id,//订单id
                    reason_id: rid,//退款原因id
                }).then(ret => {
                    if (ret.success == 1000) {
                        this.$toast('提交成功');
                        setTimeout(() => {
                            this.$backT()
                        }, 500)
                    } else {
                        if (ret.detail.phone) {
                            uni.showModal({
                            	title: '提示',
                                content: `活动马上开始，您的订单不满足退款条件，请联系客服${ret.detail.phone}`,
                                confirmText: '联系客服',
                            	success: (res) => {
                            		if (res.confirm) {
                            			this.$call(ret.detail.phone)
                            		} else if (res.cancel) {
                            			
                            		}
                            	}
                            });
                        }
                    }
                });
            },
            
            choose(item) {
                const nowStatu = item.isSelect;
                this.data.reason.forEach(ii => {
                    ii.isSelect = false;
                })
                item.isSelect =! nowStatu
            },
            
            getData() {
                this.$ajax('after_sales', {
                    user_token: this.$getSync('userToken'),
                    id: this.id,//订单id
                }).then(ret => {
                    if (ret.success == 1000) {
                        this.data = ret.detail
                        this.data.reason.forEach(cur => {
                            this.$set(cur, 'isSelect', false)
                        })
                    } else {
                        this.$toast(ret.msg);
                    }
                });
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5;
    }
    .content{
        border-top: 2rpx solid #e6e6e6;
    }
    
    .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 35rpx 20rpx;
        background-color: #fff;
        margin-bottom: 20rpx;
    }
    .img{
        width: 160rpx;
        height: 160rpx;
        border-radius: 10rpx;
        border: 2rpx solid #e6e6e6;
        margin-right: 25rpx;
    }
    .top-right{
        flex: 1;
    }
    .title{
        font-size: 30rpx;
        font-weight: bold;
        width: 500rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-bottom: 10rpx;
    }
    .time{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 7rpx 12rpx;
        background-color: #fff5ea;
        border-radius: 10rpx;
        font-size: 24rpx;
        color: #ff8400;
    }
    .time-01{
        width: 22rpx;
        height: 22rpx;
        margin-right: 10rpx;
    }
    .price{
        padding-top: 30rpx;
        font-size: 23rpx;
    }
    .price>text{
        font-size: 32rpx;
        font-weight: bold;
    }
    .box{
        background-color: #fff;
        padding: 0 20rpx;
    }
    .reason{
        font-size: 30rpx;
        font-weight: bold;
        padding: 35rpx 0;
        border-bottom: 2rpx solid #e6e6e6;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 25rpx 0;
    }
    .choose-01{
        width: 31rpx;
        height: 31rpx;
        margin-right: 20rpx;
    }
    .item-right{
        flex: 1;
    }
    
    
    
    
    .btn{
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        background-color: #40bef1;
        padding: 25rpx;
        border-radius: 50rpx;
        margin: 50rpx 20rpx;
    }

</style>
